{% extends 'mobile/base.html' %}

{% from 'questions/mobile/includes/macros.html' import questions_url with context %}

{% set styles = ('mobile-questions',) %}
{% set classes = 'questions' %}

{% if all_products %}
  {% set product_title = _('All Products') %}
{% elif multiple_products %}
  {% set product_title = _('Multiple Products') %}
{% else %}
  {% set product_title = pgettext('DB: products.Product.title', products[0].title) %}
{% endif %}

{% set title = _('{product} Support Forum')|f(product=product_title) %}
{% set headline = title %}
{% set return_url = url('questions.home') %}

{% set canonical_url = canonicalize(viewname='questions.list', product_slug=product_slug)|urlparams(None, request.GET) %}
{% if questions.number > 1 %}
  {% set canonical_url = canonical_url|urlparams(page=questions.number) %}
{% endif %}

{% set meta = (('robots', 'noindex'),) %}

{% block after_header %}
  <div class="pulldown-menu slide-on-exposed">
    <div class="pulldown-handle"></div>
    <div class="pulldown-panel">
      {#
      2018-10-17
      Temporarily remove widget due to expesive query required to get top_contributors
      https://github.com/mozilla/kitsune/issues/3373

      {% if karma_top or top_contributors %}
        <section id="top-contributors">
          <strong>{{ _('Top contributors') }}</strong>
          <ol>
            {% if top_contributors %}
              {% for result in top_contributors[:10] %}
                <li>{{ result['user']['display_name'] }}</li>
              {% endfor %}
            {% endif %}
          </ol>
        </section>
      {% endif %}
      #}
      <section id="product-switcher" class="swipeable">
        <ul>
          {% for p in product_list %}
            {% set selected = not multiple_products and p == products[0] %}
            <li{% if selected %} class="selected"{% endif %}>
              <a href="{% if selected %}{{ questions_url(_product=None) }}{% else %}{{ questions_url(_product=p.slug) }}{% endif %}">
                <span class="logo-sprite logo-{{ p.slug }}"></span>
                {{ pgettext('DB: products.Product.title', p.title) }}
              </a>
            </li>
          {% endfor %}
        </ul>
      </section>
      <section id="question-stats">
        {% trans recent_unanswered_count %}
          <strong>{{recent_unanswered_count}} question</strong> has no reply.
          {% pluralize recent_unanswered_count %}
          <strong>{{recent_unanswered_count}} questions</strong> have no reply.
        {% endtrans %}
        <span class="total">
          {{ _('Total:') }} <strong>{{ recent_asked_count }}</strong>
        </span>
        <div class="progress-bar {% if recent_answered_percent == 100 %} complete{% endif %}">
          <div style="width: {{ recent_answered_percent }}%;">
            <span>{{ recent_answered_percent }}%</span>
          </div>
        </div>
      </section>
      <section id="question-filters" class="cf">
        {{ _('Filter questions') }}
        <div class="cf">
          {% macro filter_button(title, slug) %}
            <a class="btn{% if show == slug %} selected{% endif %}"
               href="{{ request.path|urlparams(show=slug) }}">
              {{ title }}
            </a>
          {% endmacro %}

          {{ filter_button(_('Attention Needed'), 'needs-attention') }}
          {{ filter_button(_('Responded'), 'responded') }}
          {{ filter_button(_('Done'), 'done') }}
          {{ filter_button(_('Show All'), 'all') }}
        </div>
      </section>
    </div>
  </div>
{% endblock %}

{% block content %}
  <ul class="questions-list">
    {% if questions.object_list %}
      {% for question in questions.object_list %}
        <li>
          <a href="{{ question.get_absolute_url() }}">
            <span class="title">{{ question.title }}</span>
            <span>
              <strong class="replies">
                {{ question.num_answers }}
                {% trans count=question.num_answers %}
                  reply
                {% pluralize %}
                  replies
                {% endtrans %}
              </strong>
              {% if question.is_solved %}
                <strong class="solved">{{ _('solved') }}</strong>
              {% elif question.num_answers == 0 %}
                <strong class="unanswered">{{ _('needs attention') }}</strong>
              {% elif question.is_contributor(user) %}
                <strong class="contributed">{{ _('contributed') }}</strong>
              {% endif %}
            </span>
            {{ question.content_parsed|striptags()|truncate(170) }}
          </a>
        </li>
      {% endfor %}
    {% else %}
      <p class="no-questions">
        {{ _('There are no questions that match the current filter settings.') }}
      </p>
    {% endif %}
  </ul>
  {{ questions|quick_paginator }}
{% endblock %}
